//
//  TKYPhotoOrVideoView.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/27.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYPhotoOrVideoView.h"
#import "TKYPhotoOrVideoCell.h"

@implementation TKYPhotoOrVideoView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.collectionView];
        
    }
    return self;
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TKYPhotoOrVideoCell *cell= [collectionView dequeueReusableCellWithReuseIdentifier:kPhotoOrVideoCellID forIndexPath:indexPath];
    NSDictionary *dict = self.imageArr[indexPath.row];
    NSLog(@"%@",dict);
//    if ([[dict objectForKey:@"GQIsImageURL"]integerValue]== 1) {
//        cell.playButton.hidden = YES;
//    }else{
//        cell.playButton.hidden = NO;
//    }
    cell.deleteButton.hidden = YES;
    cell.backgroundColor = [UIColor grayColor];
    //cell.imageView.image = [dict objectForKey:@"image"];
    
    return cell;
}


#pragma mark--懒加载
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.itemSize = CGSizeMake(kWidthScale *100, kWidthScale *100);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 2;
        //layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
        UICollectionView *collectionView;
        
        collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kHeightScale *100) collectionViewLayout:layout];
        
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView.backgroundColor = kMainColour;
        collectionView.bounces = YES;
        //注册cell
        [collectionView registerNib:[UINib nibWithNibName:@"TKYPhotoOrVideoCell" bundle:nil] forCellWithReuseIdentifier:kPhotoOrVideoCellID];
        collectionView.scrollsToTop = NO;
        collectionView.showsVerticalScrollIndicator = NO;
        collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView = collectionView;
    }
    return _collectionView;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.seletetedCollectionCellBlock) {
        self.seletetedCollectionCellBlock(indexPath);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
